import java.util.Iterator;
import java.util.LinkedList;


public class PresentationInstance implements BasicI{
    int id;
    String title;
    String keyWords;
    int courseId;
    String user;
    int courseWeek;
    int startDate;
    int endDate;
    int duration;
    
    private Difficulty levelOfDifficulty;
    private Length length;
    private Capitalization capitalization;
    
    private LinkedList<SlideNumber> slides;
    

    public int getCourseId() {
        return courseId;
    }

    public void setCourseId(int courseId) {
        this.courseId = courseId;
    }

    public int getCourseWeek() {
        return courseWeek;
    }

    public void setCourseWeek(int courseWeek) {
        this.courseWeek = courseWeek;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public int getEndDate() {
        return endDate;
    }

    public void setEndDate(int endDate) {
        this.endDate = endDate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getKeyWords() {
        return keyWords;
    }

    public void setKeyWords(String keyWords) {
        this.keyWords = keyWords;
    }

    public int getStartDate() {
        return startDate;
    }

    public void setStartDate(int startDate) {
        this.startDate = startDate;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

     public PresentationInstance(int id,String title,String keyWords,
            int courseId,String user,int courseWeek,int startDate,
            int endDate,int duration){

        this.courseId = courseId;
        this.courseWeek = courseWeek;
        this.duration = duration;
        this.endDate = endDate;
        this.id = id;
        this.keyWords = keyWords;
        this.startDate = startDate;
        this.title = title;
        this.user = user;
        this.slides = new LinkedList<SlideNumber>();
    }
     
    // list all difficulties as options
    public String listDifficulties(){
    	StringBuffer sb = new StringBuffer();
    	for(Difficulty d : Difficulty.values()){
    		sb.append(d.getCode());
    		sb.append(": ");
    		sb.append(d.toString());
    		sb.append("\n");
    	}
    	return sb.toString();
    }

    // check if a difficulty is valid, i.e. exists as code for one option
    public boolean isDifficultyValid(int d){
    	for(Difficulty diff : Difficulty.values()){
    		if (diff.getCode() == d)
    			return true;
    	}
    	return false;
    }
    
    // set difficulty
    public void setDifficulty(int d){
    	for(Difficulty diff : Difficulty.values()){
    		if (diff.getCode() == d)
    			this.levelOfDifficulty = diff;
    	}
    }
    
    // get difficulty
    public String getLevelOfDifficulty(){
    	StringBuffer sb = new StringBuffer();
    	sb.append(this.levelOfDifficulty.getCode());
    	sb.append(" - ");
    	sb.append(this.levelOfDifficulty.toString());
    	return sb.toString();
    }
    
    // list all lengths as options
    public String listLengths(){
    	StringBuffer sb = new StringBuffer();
    	for(Length l : Length.values()){
    		sb.append(l.getCode());
    		sb.append(": ");
    		sb.append(l.toString());
    		sb.append("\n");
    	}
    	return sb.toString();
    }
    
    // check if a length is valid, i.e. exists as code for one option
    public boolean isLengthValid(int l){
    	for(Length len : Length.values()){
    		if(len.getCode() == l)
    			return true;
    	}
    	return false;
    }
    
    // set length of presentation
    public void setLength(int l){
    	for(Length len : Length.values()){
    		if (len.getCode() == l)
    			this.length = len;
    	}
    }
    
    // get the length of the presentation
    public String getLength(){
    	StringBuffer sb = new StringBuffer();
    	sb.append(this.length.getCode());
    	sb.append(" - ");
    	sb.append(this.length.toString());
    	return sb.toString();
    }
    
    // list capitalization options
    public String listCapitalization(){
    	StringBuffer sb = new StringBuffer();
    	for(Capitalization c : Capitalization.values()){
    		sb.append(c.getCode());
    		sb.append(": ");
    		sb.append(c.toString());
    		sb.append("\n");
    	}
    	return sb.toString();
    }
    
    // check if the capitalization is valid, i.e. is listed as an option
    public boolean isCapitalizationValid(int c){
    	for(Capitalization cap : Capitalization.values()){
    		if(cap.getCode() == c)
    			return true;
    	}
    	return false;
    }
    
    // set capitalization
    public void setCapitalization(int c){
    	for(Capitalization cap : Capitalization.values()){
    		if (cap.getCode() == c)
    			this.capitalization = cap;
    	}
    }
    
    // get capitalization
    public String getCapitalization(){
    	StringBuffer sb = new StringBuffer();
    	sb.append(this.capitalization.getCode());
    	sb.append(" - ");
    	sb.append(this.capitalization.toString());
    	return sb.toString();
    }

//    Show the info of the presentation
    public void showInfo(){
        System.out.println("Your choice is presentation with id:"+id+"\n Title:"
                +title+"\n Keywords:"+keyWords+"\n The course id is:"+courseId+
                "\n The lecture of the course :"+user+"\n The start date of the course is :"+
                startDate+" \n The end date of the course is:"+endDate+
                "\n The duration of the presentation is:"+duration+" minutes");
    }
    
    public void addSlide(SlideNumber s){
    	this.slides.add(s);
    }
    
    public LinkedList<SlideNumber> getPresentation(){
    	return this.slides;
    }
    
    public void displayPresentation(){
    	for(Iterator<SlideNumber> it = slides.iterator(); it.hasNext(); ){
    		SlideNumber next = it.next();
    		if((next.getSlideDifficulty().getCode() <= this.levelOfDifficulty.getCode()) &&
    		   (next.getSlideLength().getCode() <= this.length.getCode())) {
    			
    			next.displaySlide(this.capitalization.getCode());
    		}
    	}
    }
    
    public String toString(){
    	return "ID: "+id+", Title: "+title;
    }

}
